import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'stylus/index.styl'
import fastClick from 'fastclick'
import VueLazyLoad from 'vue-lazyload'
import 'babel-polyfill'
import api from '@/api/index'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import {
  Loading,
  Popup,
  Toast,
  Picker,
  Area,
  Uploader
} from 'vant'
import './assets/stylus/iconfont/iconfont.js'
// import {
//   isLogin
// } from '@/assets/js/isLogin'
import {
  getLocalStorage,
  setLocalStorage,
  removeLocalStorage
} from '@/assets/js/storage'
Vue.config.productionTip = false
fastClick.attach(document.body)
Vue.use(VueLazyLoad, {
  loading: require('@/assets/images/loading.png')
})
Vue.use(VueAwesomeSwiper)
Vue.use(Loading).use(Popup).use(Toast).use(Picker).use(Area).use(Uploader)
Vue.prototype.$api = api
Vue.prototype.$localStorage = {
  get: getLocalStorage,
  set: setLocalStorage,
  remove: removeLocalStorage
}
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

router.beforeResolve((to, from, next) => {
  const userInfo = JSON.parse(getLocalStorage('USER_INFO'))
  if (to.meta.requireAuth) {
    setLocalStorage('authUrl', to.fullPath)
    if (userInfo != null) {
      next()
    } else {
      router.push('/')
    }
  } else {
    next()
  }
})
